package com.rentao.custom.mybatis;

import java.util.HashMap;
import java.util.Map;

import org.springframework.cglib.proxy.Proxy;

/**
 * <p>MyConfiguration .
 *
 * <p>change history:
 *
 * <pre>
 * date         defect       person          comments
 * --------------------------------------------------------------------------------
 * 2025/6/29    ********     Tao Ren    create file.
 * </pre>
 *
 * @author Tao Ren
 * @date 2025/6/29 21:48
 */
public class MyConfiguration {

    //获取mapper，返回为代理类
    public <T> T getMapper(Class<?> aclass,SqlSession sqlSession) {
        //todo
        return (T) Proxy.newProxyInstance(this.getClass().getClassLoader(),
                new Class[]{aclass},
                new MapperProxy(sqlSession));
    }

    //为了方便，先将xml 定义为一个类
    static class TestMapperXml{
        //工作空间
        public static final String namespace="com.rentao.custom.mybatis.TestMapper";

        //将sql方法对应为map： id为key，对应的sql语句为value
        public static final Map<String,String> methodAndSql=new HashMap<>();

        //静态代码块为 methodAndSql 赋值
        static {
            methodAndSql.put("selectByPrimaryKey","select * from test where id =%d" );
        }
    }
}

